package com.schoolegard.services.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.schoolegard.services.AlarmClassService;
import com.schoolgard.dao.AlarmClassDao;
import com.schoolgard.entitybean.AlarmClass;

public class AlarmClassServiceImpl implements AlarmClassService {
	private static Logger logger = Logger.getLogger(AlarmClassServiceImpl.class);
	
	private AlarmClassDao alarmClassDao;

	public int saveOrUpdate(AlarmClass alramClass) {
		try{
			AlarmClass entity = alarmClassDao.createOrModify(alramClass);
			return entity == null ? 0 : entity.getId().intValue();
		} catch(Exception e) {
			logger.error("操作失败",e);
			return 0;
		}
	}

	public int delete(Long id) {
		try{
			alarmClassDao.remove(findAlarmClass(id));
			return 1;
		} catch(Exception e) {
			logger.error("操作失败",e);
			return 0;
		}
	}

	public AlarmClass findAlarmClass(Long id) {
		return alarmClassDao.findById(id);
	}

	public List<AlarmClass> findAll(int start,int limit) {
		try{
			return alarmClassDao.findAll(start, limit);
		} catch (Exception e) {
			logger.error(e);
			return new ArrayList<AlarmClass>(0);
		}
	}

	public List<AlarmClass> findAll() {
		return alarmClassDao.findAll();
	}
	
	public void setAlarmClassDao(AlarmClassDao alarmClassDao) {
		this.alarmClassDao = alarmClassDao;
	}

	public int findCount() {
		return alarmClassDao.getTotalCount();
	}

}
